package com.zy.utils.data

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint

//Line
class LinePoint(builder: Builder) : Point(builder) {

    companion object {
        const val ARROW_TYPE_NONE = 0  //无箭头
        const val ARROW_TYPE_ALL = 1  //左右箭头
        const val ARROW_TYPE_LEFT = 2  //左箭头
        const val ARROW_TYPE_RIGHT = 3  //右箭头

        private const val ARROW_D = 20
    }

    private val listPaint = Paint()

    init {
        //设置文本大小
        listPaint.textSize = 48f
        listPaint.isAntiAlias = true
        listPaint.strokeWidth = 5f
        //设置文本对齐方式
        listPaint.textAlign = Paint.Align.CENTER
        listPaint.color = Color.BLUE
    }

    //箭头：无箭头，左右箭头，双箭头
    //方向：0 -> 360


    override fun drawV(canvas: Canvas, paint: Paint) {
        //无箭头
        canvas.drawLine(centerX - per, centerY, centerX + per, centerY, listPaint)
        when (arrowType) {
            ARROW_TYPE_ALL -> {
                drawRightArrow(canvas, listPaint)
                drawLeftArrow(canvas, listPaint)
            }
            ARROW_TYPE_LEFT -> {
                drawLeftArrow(canvas, listPaint)
            }
            ARROW_TYPE_RIGHT -> {
                drawRightArrow(canvas, listPaint)
            }
        }
    }


    //右箭头
    private fun drawRightArrow(canvas: Canvas, paint: Paint) {
        canvas.drawLine(
            centerX + per - ARROW_D,
            centerY - ARROW_D,
            centerX + per,
            centerY,
            paint
        )
        canvas.drawLine(
            centerX + per - ARROW_D,
            centerY + ARROW_D,
            centerX + per,
            centerY,
            paint
        )
    }


    //左箭头
    private fun drawLeftArrow(canvas: Canvas, paint: Paint) {
        canvas.drawLine(
            centerX - per,
            centerY,
            centerX - per + ARROW_D,
            centerY - ARROW_D,
            paint
        )
        canvas.drawLine(
            centerX - per,
            centerY,
            centerX - per + ARROW_D,
            centerY + ARROW_D,
            paint
        )
    }

    override fun drawBackground(canvas: Canvas, paint: Paint) {
        //super.drawBackground(canvas, paint)
    }

    override fun drawCircle(canvas: Canvas, paint: Paint) {

    }
}